package javabase.concurrent;

import java.util.Date;
import java.util.Random;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class TimeoutWaitWitchCondition {


    private static final Lock LOCK = new ReentrantLock();
    private static final Condition CONDITION = LOCK.newCondition();
    private static final Random RANDOM = new Random();

    public static void main(String[] args) {
        Thread t = new Thread(() -> {
           for (;;) {
               LOCK.lock();
               try {
                   if (RANDOM.nextBoolean()) {
                       CONDITION.signal();
                   }
               } finally {
                   LOCK.unlock();
               }
           }
        });

        t.setDaemon(true);
        t.start();
        waiter(10000);
    }

    private static void waiter(long timeout) {
        final Date deadline = new Date(System.currentTimeMillis() + timeout);

    }


}
